$(function(){
	initPersonalInforForm();
	//获取个人信息表
	function initPersonalInforForm (){
	   var archivesId= utilModule.getQueryString("archivesid");
	    var params = {"archivesid":archivesId};
	    electronicArchivesMdule.personalinforForm(params,function(callBack){
	    	console.log(callBack);
	    	if(callBack){
	    		var infor = callBack.patientBasicInfo;
	    		
	    		if(utilModule.checkUndefined(infor)!="") {
	    			//姓名
		    		$(".name").text(infor.name);
		    		//性别
		    		var $sex = infor.sex;
		    		if(infor.sex==1){
		    			$sex = "男";
		    		}else if(infor.sex==2){
		    			$sex = "女";
		    		}else if(infor.sex==9){
		    			$sex = "未说明的性别";
		    		}else if(infor.sex==0){
		    			$sex = "未知的性别";
		    		}
		    		$(".sex").text($sex);
		    		//出生日期
		    		$(".birthday").text(infor.birthday);
		    		//身份证号
		    		$(".idcard").text(infor.idcard);
		    		//本人电话
		    		$(".personal-phone").text(infor.phone);
		    		//联系人 姓名
		    		$(".concactren-name").text(infor.contactrenname);
		    		//联系人电话
		    		$(".concactrentelephone").text(infor.contactrenphone);
		    		//户籍
		    		var $permanenttype = infor.permanenttype;
		    		if(infor.permanenttype==1){
		    			$permanenttype ="户籍";
		    		}else if(infor.permanenttype==2){
		    			$permanenttype ="非户籍";
		    		}
		    		$(".isResident").text($permanenttype);
		    		//民族
		    		var national = JSON.parse(infor.nation);
		    		console.log(national);
		    		var $nation = national.name;
		    		if(national.code==01){
		    			$nation ="汉族";
		    		}
		    		if(national.code==99){
		    			$nation ="少数民族("+national.name+")";
		    		}
		    		$(".nation").text($nation);
		    		//血型
		    		var bloodType = JSON.parse(infor.blood),
		    		$bloodType = bloodType.type,
		    		$bloodRh = bloodType.rhtype;
		    		if($bloodRh==1){
		    			bloodType.rhtype = "阴性";
		    		}else if($bloodRh==2){
		    			bloodType.rhtype = "阳性";
		    		}else if($bloodRh==3){
		    			bloodType.rhtype = "不详";
		    		}
		    		 
		    		if(bloodType.type==1){
		    			$bloodType = "A型";
		    		}else if(bloodType.type==2){
		    			$bloodType = "B型";
		    		}else if(bloodType.type==3){
		    			$bloodType = "O型";
		    		}else if(bloodType.type==4){
		    			$bloodType = "AB型";
		    		}else if(bloodType.type==5){
		    			$bloodType = "不详";
		    		}
		    		$(".blood").text($bloodType+"("+bloodType.rhtype+")");
		    		//工作单位
		    		$(".work-unit").text(infor.workunit);
		    		//文化程度
		    		var $education = infor.education;
		    		if(infor.education==1){
		    			$education = "研究生";	
		    		}else if(infor.education==2) {
		    			$education = "大学本科";
		    		}else if(infor.education==3) {
		    			$education = "大学专科和专科学校";
		    		}else if(infor.education==4) {
		    			$education = "中等专业学校";
		    		}else if(infor.education==5) {
		    			$education = "技工学校";
		    		}else if(infor.education==6) {
		    			$education = "高中";
		    		}else if(infor.education==7) {
		    			$education = "初中";
		    		}else if(infor.education==8) {
		    			$education = "小学";
		    		}else if(infor.education==9) {
		    			$education = "文盲或半文盲";
		    		}else if(infor.education==10) {
		    			$education = "不详";
		    		}
		    		$(".education").text($education);
		    		//职业
		    		var $occupation = infor.occupation;
		    		if(infor.occupation==0){
		    			$occupation = "国家机关、党群组织、企业、事业单位负责人";
		    		} else if(infor.occupation==1){
		    			$occupation = "专业技术人员";
		    		}else if(infor.occupation==2){
		    			$occupation = "办事人员和有关人员";
		    		}else if(infor.occupation==3){
		    			$occupation = "商业、服务业人员";
		    		}else if(infor.occupation==4){
		    			$occupation = "农、林、牧、渔、水利业生产人员";
		    		}else if(infor.occupation==5){
		    			$occupation = "生产、运输设备操作人员及有关人员";
		    		}else if(infor.occupation==6){
		    			$occupation = "军人";
		    		}else if(infor.occupation==7){
		    			$occupation = "不便分类的其他从业人员";
		    		}else if(infor.occupation==8){
		    			$occupation = "无职业";
		    		}
		    		$(".occupation").text($occupation);
		    		//婚姻状况
		    		var $marital = infor.marital;
		    		if(infor.marital==1){
		    			$marital = "未婚";
		    		}else if(infor.marital==2){
		    			$marital = "已婚";
		    		}else if(infor.marital==3){
		    			$marital = "丧偶";
		    		}else if(infor.marital==4){
		    			$marital = "离婚";
		    		}else if(infor.marital==5){
		    			$marital = "未说明的婚姻状况";
		    		}
		    		$(".marital").text($marital);
		    		
		    		//支付方式
		    		var payType = JSON.parse(infor.paytype),
		    		$paytype = payType.select.split(",");
		    		for(var i=0;i<$paytype.length;i++){
		    			var Paytype = $paytype[i];
		    			for(var j =0; j<Paytype.length;j++){
		    				var payNum = Paytype[j];
			    			var $payType = payNum;
			    			if(payNum==1){
			    				$payType = "城镇职工基本医疗保险";
			    			}else if(payNum==2){
			    				$payType = "城镇居民基本医疗保险";
			    			}else if(payNum==3){
			    				$payType = "新型农村合作医疗";
			    			}else if(payNum==4){
			    				$payType = "贫困救助";
			    			}else if(payNum==5){
			    				$payType = "商业医疗保险";
			    			}else if(payNum==6){
			    				$payType = "全公费";
			    			}else if(payNum==7){
			    				$payType = "全自费";
			    			}else if(payNum==8){
			    				$payType = "其他("+ payType.text +")";
			    			}
		    				var html = "<li>"+ Paytype[j]+". "+$payType+"</li>"
			    		}
		    			$(".paytype").append(html);
		    		}
		    		//药物过敏史
		    		var AllErgy = JSON.parse(infor.allergy);
		    		var commententContact = AllErgy.text;
		    		var $allergy = AllErgy.select.split(",");
		    		for(var i=0;i<$allergy.length;i++){
		    			var allergy = $allergy[i];
		    			for(var j =0;j<allergy.length;j++){
		    				if(allergy[j]==1){
		    					Allergy = "无";
			    			}else if(allergy[j]==2){
			    				Allergy = "青霉素";
			    			}else if(allergy[j]==3){
			    				Allergy = "磺胺";
			    			}else if(allergy[j]==4){
			    				Allergy = "链霉素";
			    			}else if(allergy[j]==5){
			    				Allergy = "其他("+commententContact+")";
			    			}
			    			var html = "<li>"+allergy[j]+". "+Allergy+"</li>";
			    			
		    			}
		    			$(".allergy").append(html);
		    		}
		    		// 暴露史
		    		var ExPosure = infor.exposure;
		    		var $exposure = ExPosure.split(",");
		    		for(var i=0;i<$exposure.length;i++){
		    			var Exposure = $exposure[i];
		    			for(var j=0;j<Exposure.length;j++){
		    				var ExP  = Exposure[j];
		    				if(Exposure==1){
		    					ExP = "无";
		    				}
			    			if(Exposure==2){
			    				ExP = "化学品";
			    			}
			    			if(Exposure==3){
			    				ExP = "毒物";
			    			}
			    			if(Exposure==4){
			    				ExP = "射线";
			    			}
			    			var html = "<li>"+Exposure[j]+". "+ExP+"</li>"
		    			}
		    			$(".exposure").append(html);
		    		}
		    		//疾病  
		    		var disease = JSON.parse(infor.disease);
		    		console.log(disease.length);
		    		for(var i=0;i<disease.length;i++){
		    			var disInfor = disease[i];
		    			var $beizhu =disInfor.beizhu;
		    			var disInforType = disInfor.type;
		    			if(disInfor.type==1){
		    				disInforType = "无";
		    			}else if(disInfor.type==2){
		    				disInforType = "高血压";
		    			}else if(disInfor.type==3){
		    				disInforType = "糖尿病";
		    			}else if(disInfor.type==4){
		    				disInforType = "冠心病";
		    			}else if(disInfor.type==5){
		    				disInforType = "慢性阻塞性肺疾病";
		    			}else if(disInfor.type==6){
		    				disInforType = "恶性肿瘤("+$beizhu+")";
		    			}else if(disInfor.type==7){
		    				disInforType = "脑卒中";
		    			}else if(disInfor.type==8){
		    				disInforType = "严重精神障碍";
		    			}else if(disInfor.type==9){
		    				disInforType = "结核病";
		    			}else if(disInfor.type==10){
		    				disInforType = "肝炎";
		    			}else if(disInfor.type==11){
		    				disInforType = "其他法定传染病";
		    			}else if(disInfor.type==12){
		    				disInforType = "职业病("+$beizhu+")";
		    			}else if(disInfor.type==13){
		    				
		    				disInforType = "其他("+$beizhu+")";
		    			}
		    			var html = "<li><span>"+disInforType+"</span><div>"+disInfor.date+"</div></li>";
		    			$(".disease").append(html);
		    		}
		    
		    		//手术
		    		var Operation = JSON.parse(infor.operation);
		    		console.log(Operation);
		    		var selectNum = Operation.select;
		    		delete Operation["select"];
		    		
					for(var js2 in Operation){
						console.log(js2+"="+Operation[js2]);
					}
					var jslength=0;
					for(var js2 in Operation){
						jslength++;
					}
					console.log(jslength);
					var shhtml;
		    		if(selectNum==2){
		    			/*if(jslength==4){
		    				var shhtml="<li><span>"+Operation.name0+"</span><div>"+Operation.datetime0+"</div></li><li><span>"+Operation.name1+"</span><div>"+Operation.datetime1+"</div></li>";	
		    			}*/
		    			if(jslength==2){
		    				var shhtml="<li style='height:50px;'><span>"+Operation.name+"</span><div>"+Operation.datetime+"</div></li>";	
		    			}
		    		}else if(selectNum==1){
		    			var shhtml ="<li>无</li>";
		    		}
		    		$(".operation").append(shhtml);
		    		
		    		
		    		//外伤 
		    		var trauma = JSON.parse(infor.trauma);
		    		//console.log(trauma);
		    		var selectNum = trauma.select;
		    		 delete trauma["select"];
					for(var js2 in trauma){
						//console.log(js2+"="+trauma[js2]);
					}
					var jslength=0;
					for(var js2 in trauma){
						jslength++;
					}
					var shhtml;
		    		if(selectNum==2){
		    			/*if(jslength==4){
		    				var shhtml="<li><span>"+trauma.name+"</span><div>"+trauma.datetime+"</div></li><li><span>"+trauma.name1+"</span><div>"+trauma.datetime1+"</div></li>";	
		    			}*/
		    			if(jslength==2){
		    				var shhtml="<li style='height:50px;'><span>"+trauma.name+"</span><div>"+trauma.datetime+"</div></li>";	
		    			}
		    		}else if(selectNum==1){
		    			var shhtml ="<li>无</li>";
		    		}
		    		$(".trauma").append(shhtml);
		    		
		    		
		    		//输血
		    		var profession =JSON.parse(infor.transfusion);
		    		console.log(profession);
		    		var selectNum = profession.select;
		    		 delete profession["select"];
		    		
					for(var js2 in profession){
						//console.log(js2+"="+profession[js2]);
					}
					var jslength=0;
					for(var js2 in profession){
						jslength++;
					}
					var shhtml;
		    		if(selectNum==2){
		    			/*if(jslength==4){
		    				var shhtml="<li><span>"+profession.name+"</span><div>"+profession.datetime+"</div></li><li><span>"+profession.name1+"</span><div>"+profession.datetime1+"</div></li>";	
		    			}*/
		    			if(jslength==2){
		    				var shhtml="<li style='height:50px;'><span>"+profession.name+"</span><div>"+profession.datetime+"</div></li>";	
		    			}
		    		}else if(selectNum==1){
		    			var shhtml ="<li style='height:50px;'>无</li>";
		    		}
		    		$(".transfusion").append(shhtml);
		    		// 家族疾病
		    		var  familyhistory = JSON.parse(infor.familyhistory);
		    		//console.log(familyhistory);
		    		if(familyhistory.fatherselect){
		    			$(".familyhistory .relationName1").text("父亲");
		    		}
		    		if(familyhistory.motherselect){
		    			$(".familyhistory .relationName2").text("母亲");
		    		}
		    		if(familyhistory.compatriotselect){
		    			$(".familyhistory .relationName3").text("兄弟姐妹");
		    		}
		    		if(familyhistory.childrenselect){
		    			$(".familyhistory .relationName4").text("子女");
		    		}
		    		//父亲
		    		var fatherSelect =familyhistory.fatherselect.split(",");
		    		//console.log(fatherSelect);
		    		//console.log(familyhistory.fathertext);
		    		if(fatherSelect){
		    			$(".fatherhistory").show();
		    			for(var i=0;i<fatherSelect.length;i++){
		    				var Fath = fatherSelect[i];
		    				if(fatherSelect[i]==1){
		    					Fath = "无";
		    				}else if(fatherSelect[i]==2){
		    					Fath = "高血压";
		    				}else if(fatherSelect[i]==3){
		    					Fath = "糖尿病";
		    				}else if(fatherSelect[i]==4){
		    					Fath = "冠心病";
		    				}else if(fatherSelect[i]==5){
		    					Fath = "慢性阻塞性肺疾病";
		    				}else if(fatherSelect[i]==6){
		    					Fath = "恶性肿瘤";
		    				}else if(fatherSelect[i]==7){
		    					Fath = "脑卒中";
		    				}else if(fatherSelect[i]==8){
		    					Fath = "严重精神障碍";
		    				}else if(fatherSelect[i]==9){
		    					Fath = "结核病";
		    				}else if(fatherSelect[i]==10){
		    					Fath = "肝炎";
		    				}else if(fatherSelect[i]==11){
		    					Fath = "先天畸形";
		    				}else if(fatherSelect[i]==12){
			    				Fath = "其他("+familyhistory.fathertext+")";
		    				}
		    				var html = "<li>"+fatherSelect[i]+". "+Fath+"</li>";
		    				$(".familyhistory .fatherhistory").append(html);
		    			}
		    		}
		    		//母亲
		    		var motherSelect =familyhistory.motherselect.split(",");
		    		//console.log(motherSelect);
		    		//console.log(familyhistory.mothertext);
		    		if(motherSelect){
		    			$(".motherhistory").show();
		    			for(var i=0;i<motherSelect.length;i++){
		    				var Moth = motherSelect[i];
		    				if(motherSelect[i]==1){
		    					Moth  = "无";
		    				}else if(motherSelect[i]==2){
		    					Moth  = "高血压";
		    				}else if(motherSelect[i]==3){
		    					Moth  = "糖尿病";
		    				}else if(motherSelect[i]==4){
		    					Moth  = "冠心病";
		    				}else if(motherSelect[i]==5){
		    					Moth  = "慢性阻塞性肺疾病";
		    				}else if(motherSelect[i]==6){
		    					Moth  = "恶性肿瘤";
		    				}else if(motherSelect[i]==7){
		    					Moth  = "脑卒中";
		    				}else if(motherSelect[i]==8){
		    					Moth  = "严重精神障碍";
		    				}else if(motherSelect[i]==9){
		    					Moth  = "结核病";
		    				}else if(motherSelect[i]==10){
		    					Moth  = "肝炎";
		    				}else if(motherSelect[i]==11){
		    					Moth  = "先天畸形";
		    				}else if(motherSelect[i]==12){
			    				Moth  = "其他("+familyhistory.mothertext+")";
		    				}
		    				var html = "<li style='height:50px;'>"+motherSelect[i]+". "+Moth +"</li>";
		    				$(".familyhistory .motherhistory").append(html);
		    			}
		    		}
		    		//兄弟姐妹
		    		var compatriotSelect =familyhistory.compatriotselect.split(",");
		    		//console.log(compatriotSelect);
		    		//console.log(familyhistory.compatriottext);
		    		if(compatriotSelect){
		    			$(".compatriothistory").show();
		    			for(var i=0;i<compatriotSelect.length;i++){
		    				var Moths = compatriotSelect[i];
		    				if(compatriotSelect[i]==1){
		    					Moths  = "无";
		    				}else if(compatriotSelect[i]==2){
		    					Moths  = "高血压";
		    				}else if(compatriotSelect[i]==3){
		    					Moths  = "糖尿病";
		    				}else if(compatriotSelect[i]==4){
		    					Moths  = "冠心病";
		    				}else if(compatriotSelect[i]==5){
		    					Moths  = "慢性阻塞性肺疾病";
		    				}else if(compatriotSelect[i]==6){
		    					Moths  = "恶性肿瘤";
		    				}else if(compatriotSelect[i]==7){
		    					Moths  = "脑卒中";
		    				}else if(compatriotSelect[i]==8){
		    					Moths  = "严重精神障碍";
		    				}else if(compatriotSelect[i]==9){
		    					Moths  = "结核病";
		    				}else if(compatriotSelect[i]==10){
		    					Moths  = "肝炎";
		    				}else if(compatriotSelect[i]==11){
		    					Moths  = "先天畸形";
		    				}else if(compatriotSelect[i]==12){
			    				Moths  = "其他("+familyhistory.compatriottext+")";	
		    				}
		    				var html = "<li style='height:50px;'>"+compatriotSelect[i]+". "+Moths +"</li>";
		    				$(".familyhistory .compatriothistory").append(html);
		    			}
		    		}
		    		//子女
		    		var childrenSelect =familyhistory.childrenselect.split(",");
		    		//console.log(childrenSelect);
		    		//console.log(familyhistory.childrentext);
		    		if(childrenSelect){
		    			$(".childrenhistory").show();
		    			for(var i=0;i<childrenSelect.length;i++){
		    				
		    				var Mothed = childrenSelect[i];
		    				if(childrenSelect[i]==1){
		    					Mothed  = "无";
		    				}else if(childrenSelect[i]==2){
		    				    Mothed  = "高血压";
		    				}else if(childrenSelect[i]==3){
		    					Mothed  = "糖尿病";
		    				}else if(childrenSelect[i]==4){
		    					Mothed  = "冠心病";
		    				}else if(childrenSelect[i]==5){
		    					Mothed  = "慢性阻塞性肺疾病";
		    				}else if(childrenSelect[i]==6){
		    					Mothed  = "恶性肿瘤";
		    				}else if(childrenSelect[i]==7){
		    					Mothed  = "脑卒中";
		    				}else if(childrenSelect[i]==8){
		    					Mothed  = "严重精神障碍";
		    				}else if(childrenSelect[i]==9){
		    					Mothed = "结核病";
		    				}else if(childrenSelect[i]==10){
		    					Mothed  = "肝炎";
		    				}else if(childrenSelect[i]==11){
		    					Mothed  = "先天畸形";
		    				}else if(childrenSelect[i]==12){
			    				Mothed  = "其他("+familyhistory.childrentext+")";	
		    				}
		    				var html = "<li style='height:50px;'>"+childrenSelect[i]+". "+Mothed +"</li>";
		    				$(".familyhistory .childrenhistory").append(html);
		    			}
		    		}
		    		
		    		// 残疾
		    		var Disability = JSON.parse(infor.disability);
		    		var $disability = Disability.select.split(",");
		    		for(var i=0;i<$disability.length;i++){
		    			var disAbility = $disability[i];
		    			for(var j=0;j<disAbility.length;j++){
		    				var disability = disAbility[j];
		    				if(disAbility[j]==1){
		    					disability = "无残疾";
		    				}else if(disAbility[j]==2){
		    					disability = "视力残疾";
		    				}else if(disAbility[j]==3){
		    					disability = "听力残疾";
		    				}else if(disAbility[j]==4){
		    					disability = "言语残疾";
		    				}else if(disAbility[j]==5){
		    					disability = "肢体残疾";
		    				}else if(disAbility[j]==6){
		    					disability = "智力残疾";
		    				}else if(disAbility[j]==7){
		    					disability = "精神残疾";
		    				}else if(disAbility[j]==8){
		    					disability = "其他残疾("+Disability.text+")";
		    				}
			    			var html = "<li style='height:50px;'>"+disAbility[j]+". "+disability+"</li>";	
		    			}
		    			$(".disability").append(html);
		    		}
		    		
		    		
		    		//遗传病史
		    		 var heredity  = JSON.parse(infor.heredity);
		    		// console.log(heredity);
		    		 if(heredity.select==2){
		    		 	var html ="<li>"+"有("+heredity.text+")"+"</li>";
		    		 }else{
		    		 	var html ="<li>无</li>";
		    		 }
		    		$(".heredity").append(html);
		    		//生活环境
		    		var environmental = JSON.parse(infor.environment);
		    		//console.log(environmental);
		    		var $exhaustair = environmental.exhaustair,
		    		$fueltype = environmental.fueltype,
		    		$water = environmental.water,
		    		$toilet = environmental.toilet,
		    		$poultry = environmental.poultry;
		    		
		    		if(environmental.exhaustair==1){
		    			$exhaustair = "无";
		    		}else if(environmental.exhaustair==2){
		    			$exhaustair = "油烟机";
		    		}else if(environmental.exhaustair==3){
		    			$exhaustair = "换气扇";
		    		}else if(environmental.exhaustair==4){
		    			$exhaustair = "烟囱";
		    		}
		    		$(".exhaustair").text($exhaustair);
		    		if(environmental.fueltype==1){
		    			$fueltype="液化气";
		    		}else if(environmental.fueltype==2){
		    			$fueltype="煤";
		    		}else if(environmental.fueltype==3){
		    			$fueltype="天然气";
		    		}else if(environmental.fueltype==4){
		    			$fueltype="沼气";
		    		}else if(environmental.fueltype==5){
		    			$fueltype="柴火";
		    		}else if(environmental.fueltype==6){
		    			$fueltype="其他";
		    		}
		    		$(".fueltype").text($fueltype);
		    		if(environmental.water==1){
		    			$water="自来水";
		    		}else if(environmental.water==2){
		    			$water="经净化过滤的水";
		    		}else if(environmental.water==3){
		    			$water="井水";
		    		}else if(environmental.water==4){
		    			$water="河湖水";
		    		}else if(environmental.water==5){
		    			$water="塘水";
		    		}else if(environmental.water==6){
		    			$water="其他";
		    		}
		    		$(".water").text($water);
		    		
		    		if(environmental.toilet==1){
		    			$toilet="卫生厕所";
		    		}else if(environmental.toilet==2){
		    			$toilet="一格或二格粪池式";
		    		}else if(environmental.toilet==3){
		    			$toilet="马桶";
		    		}else if(environmental.toilet==4){
		    			$toilet="露天粪坑";
		    		}else if(environmental.toilet==5){
		    			$toilet="简易棚厕";
		    		}
		    		$(".toilet").text($toilet);
		    		if(environmental.poultry==1){
		    			$poultry="无";
		    		}else if(environmental.poultry==2){
		    			$poultry="单设";
		    		}else if(environmental.poultry==3){
		    			$poultry="室内";
		    		}else if(environmental.poultry==4){
		    			$poultry="室外";
		    		}
		    		$(".poultry").text($poultry);
		    	}
    		}
	    		
	    })
	}

$(".html-loding").hide();

});
